﻿using System;
using PSE.Deployment.Engine;
using PSE.Deployment.Engine.Enums;
using PSE.Deployment.Engine.Interfaces;

namespace Sinacor.Deployment.Setup.Wizard.Steps
{
    public class DataBaseCompany: BaseStep
    {
        private UI.CompanySelection companySelection;
        public StepNavigationAction NavigationAction { get; protected set; }

        public DataBaseCompany(IStepGroup parent)
            :base(parent)
        {
            this.Id = "DataBaseCompany";
            this.ErrorBehavior = PSE.Deployment.Engine.Enums.StepErrorBehavior.NotifyParent;
            this.NavigationBehavior = PSE.Deployment.Engine.Enums.StepNavigationBehavior.NextPreviousCancel;

            this.ExecutionFinished += new EventHandler<PSE.Deployment.Engine.CustomEventArgs.ExecutionFinishedEventArgs>(DataBaseCompany_ExecutionFinished);

        }

        void DataBaseCompany_ExecutionFinished(object sender, PSE.Deployment.Engine.CustomEventArgs.ExecutionFinishedEventArgs e)
        {
            e.NavigationAction = this.NavigationAction;
        }

        public override void Execute()
        {
            companySelection = new UI.CompanySelection();
            companySelection.ShowDialog();
            this.NavigationAction = companySelection.NavigationAction.GetValueOrDefault();
        }

        public override void Undo()
        {
            if (companySelection != null)
                companySelection.Close(false);
        }
    }
}
